package com.wfg.flink.connector.mongodb.com;

import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import org.bson.types.ObjectId;

import java.lang.reflect.Type;

/**
 * @author wfg
 */
public class ObjectIdObjectWriter implements ObjectWriter<ObjectId> {

    @Override
    public void write(JSONWriter jsonWriter, Object o, Object o1, Type type, long l) {
        if (o == null) {
            jsonWriter.writeNull();
            return;
        }
        ObjectId objectId = (ObjectId) o;
        jsonWriter.writeString(objectId.toHexString());
    }
}